package org.mnj07.jms.topic.selector;

import javax.annotation.Resource;
import javax.jms.*;

public class Sender
{
  @Resource(lookup = "jms/javaee6/ConnectionFactory")
  private static ConnectionFactory connectionFactory;
  @Resource(lookup = "jms/javaee6/Topic")
  private static Topic topic;
  
  public static void main(String[] args) {

    try {
        // Creates the needed artifacts to connect to the queue
        Connection connection = connectionFactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(topic);

        // Sends a text message to the topic
        TextMessage message = session.createTextMessage();


        String body;
        for (int i = 0; i < 10; i++) {
            message.setIntProperty("orderAmount", i);
            body = "This is a text message with orderAmound" + i;
            System.out.println(body);
            message.setText(body);
            producer.send(message);
            message.acknowledge();
        }

        connection.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

    System.exit(0);
  }
}
